$(document).ready(function(){
    var ipt = $('.purch');
    ipt.on('keyup',function(){
        if(! /^\d+$/.test(this.value)){
            this.value='';
        }
    })

	console.log('111111111111');
});

var discount_price = $(".price_all").val();
var price_all=$(".price_all").val();
layui.use('table', function() {
	var table = layui.table;
    var purch=$(".purch").val();
    var price_all=$(".price_all").val();
    $(".purch").keyup(function(){
        myFunction();
    });

    function myFunction(){
        var purch=$(".purch").val();

        if(purch !=1)
        {
            Price = purch*price_all;
            $(".price_all").val(Price);
		}else{
            $(".purch").val(1);
            $(".price_all").val(discount_price);
		}
    }


    $(".go_btn").click(function() {
		var price = $(".price_all").val();
       	var purch =$(".purch").val();
		var patrn1 = /^[a-zA-Z0-9]{1}([a-zA-Z0-9]|[._,+-@#$%^&*()~`]){2,20}$/;
        var code = '';
        var product = $("#product").val();

		if(purch =="" || purch ==0){
            layer.msg("请输入购买数量", {
                icon: 3,
                time: 2000 //2秒关闭（如果不配置，默认是3秒）
            });
            $(".purch").val(1);
            $(".price_all").val(discount_price);
            return false;
		}

		var index = layer.load(2, {
			shade: [0.2, '#1d89fb'] //0.1透明度的白色背景
				,
			time: 500,
			end: function(e) {
                window.location.href ='/createOrder?month='+purch+'&code='+code+'&product='+product;
            }
		});

	})

})